package net.coldsky.common.util.io;

import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * IO操作的辅助工具<p>
 * 如关闭多个	java.io.Closeable
 * 刷新多个	java.io.Flushable
 * */
public class IOUtils {
	
	protected final static Log log = LogFactory.getLog(IOUtils.class);
	
	/**
	 * 关闭多个 java.io.Closeable
	 * @param closeables
	 */
	public static void close(Closeable...closeables) {
		if (closeables != null && closeables.length > 0) {
			for(Closeable closeable:closeables){
				try {
					if(closeable != null){
						closeable.close();
					}
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
	}

	/**
	 * 刷新多个 java.io.Flushable
	 * @param flushables
	 */
	public static void flush(Flushable...flushables) {
		if (flushables != null && flushables.length <= 0) {	return;}
		
		for(Flushable flushable:flushables){
			try {
				if(flushable != null){
					flushable.flush();
				}
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
		}
	}

	
}
